<%@page import="com.crossriver.crgis.database.service.persistence.Application_C_of_OUtil"%>
<%@page import="com.crossriver.crgis.database.model.Application_C_of_O"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.crossriver.crgis.database.model.Company_Contact_Person"%>
<%@ page import="com.crossriver.crgis.cofo.util.ApplicationCofOConstants" %>

<%@ include file="/init.jsp"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:renderURL var="ApplicationCofO1">
		<portlet:param name="jspPage" value="/html/individualcofo/ApplicationCofO1.jsp" />
</portlet:renderURL>
<portlet:renderURL var="ApplicationCofO3">
		<portlet:param name="jspPage" value="/html/individualcofo/ApplicationCofO3.jsp" />
</portlet:renderURL>

<%
Company_Contact_Person contactInfo =
		(Company_Contact_Person)request.getAttribute(
					ApplicationCofOConstants.COY_CONTACT_SESSION_ATTR);
Application_C_of_O applicatn = 
	Application_C_of_OUtil.findByPrimaryKey(contactInfo.getApplicationId());
Application_C_of_O appl =
	(Application_C_of_O)request.getAttribute(
			ApplicationCofOConstants.APPL_C_OF_O_SESSION_ATTR);

%>

<liferay-portlet:actionURL name="saveCompanyContactInformation" var="saveCompanyContactInformation"></liferay-portlet:actionURL>



<aui:form action="<%=saveCompanyContactInformation.toString() %>" method="post" name="saveCompanyContactInformation_fm">
 	
	<% String app = applicatn.getApplication(); %>
 <div id="main">
	<%
	if("certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Certificate Of Occupancy</h1>
	<%
	}else if("re-certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Re-Certificate Of Occupancy</h1>
	<%
	}else {
	%>
	<h1>Application for State Land</h1>
	<%
	}
	%>
	
	
 
  <div class="content">
  <liferay-ui:error key="designation-is-mandatory" message="designation-is-mandatory" />
	<liferay-ui:error key="email-is-mandatory" message="email-is-mandatory" />
	<liferay-ui:error key="title-is-mandatory" message="title-is-mandatory" />
	<liferay-ui:error key="last-name-is-mandatory" message="last-name-is-mandatory" />
	<liferay-ui:error key="first-name-is-mandatory" message="first-name-is-mandatory" />
	<liferay-ui:error key="mobile-no-mandatory" message="mobile-no-mandatory" />
	<liferay-ui:error key="identification-doc-is-mandatory" message="identification-doc-is-mandatory" />
	<liferay-ui:error key="identification-no-is-mandatory" message="identification-no-is-mandatory" />
	<liferay-ui:error key="email-is-not-valid" message="email-is-not-valid" />
	<liferay-ui:success key="company-contact-save-success" message="company-contact-save-success"></liferay-ui:success>
  
  	<table width="100%" border="0" cellpadding="0" cellspacing="0">
   	<tr>
     	<td width="15%" valign="top">
     		<aui:input name="applicationId" type="hidden" value="<%= contactInfo.getApplicationId() %>"></aui:input>
    		<aui:input name="buttonClicked" type="hidden" value=""></aui:input>
    		<table width="100%" id="steps" cellpadding="0" cellspacing="0">
       		<tr><td valign="middle" align="center">STEP 1</td></tr>
       		<tr><td valign="middle" align="center" class="current">STEP 2</td></tr>
	        <tr><td valign="middle" align="center">STEP 3</td></tr>
          <tr><td valign="middle" align="center">STEP 4</td></tr>
          <tr><td valign="middle" align="center">STEP 5</td></tr>
          <tr><td valign="middle" align="center">STEP 6</td></tr>
          <tr><td valign="middle" align="center">STEP 7</td></tr>
          <tr><td valign="middle" align="center">STEP 8</td></tr>                               
       	</table>
    	</td>
      <td width="85%" valign="top">
     		<table width="100%" id="mainform">
        	<tr>
        			<td class="title" colspan="3">Organisation/Company Contact Person</td>
           </tr>
           <tr>
           	<td colspan="3" align="right" class="buttons">
            	<hr>
            	<aui:button type="button" value="Exit Application" onClick="exitApplication();"></aui:button>
             	<aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
            	<aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
             	<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
          	</td>
          </tr>    	
    			
    			<tr>
      			<td><br>
	           
         		<%
         	
         			List<ListType> designations = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.designation");
		
						%>
					
						<aui:select style="width:130px" name="designation" label="Designation<span class='mandatoryfld'>*</span>" listType="dropdownlist" >
							<option value="">Please Select Designation</option>
				  	
					  	<%
					  	String designation = contactInfo.getDesignation();
					  	for(int i=0; i<designations.size(); i++){
					  		ListType _designation = designations.get(i);
					  	%>	
				  		<aui:option selected="<%= _designation.getName().equalsIgnoreCase(designation)  %>" value="<%=_designation.getName() %>"><%=_designation.getName()  %></aui:option>
					  	<%
					  	}
					  	%>
						</aui:select>
						
      			</td>
	      		<td colspan="2"><br>
	      		
							<%
							List<ListType> greetings = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.title");
							
							%>
					
							<aui:select name="title" label="Title<span class='mandatoryfld'>*</span>" listType="dropdownlist" >
								<option value="">Select Your Title</option>
				  	
						  	<%
						  	String greeting = contactInfo.getTitle();
						  	for(int i=0; i<greetings.size(); i++){
						  		ListType _greeting = greetings.get(i);
						  	%>	
				  			<aui:option selected="<%= _greeting.getName().equalsIgnoreCase(greeting)  %>" value="<%=_greeting.getName() %>"><%=_greeting.getName()  %></aui:option>
						  	<%
						  	}
						  	%>
						</aui:select>
	      		</td>
  				</tr>
					<tr>
						<td width="33%"><br>
						  <aui:input label="Last name<span class='mandatoryfld'>*</span>" 
								name="lastName" 
								value="<%= contactInfo.getLastName() %>"
								helpMessage=""></aui:input>
						</td>
						<td width="33%"><br>
					    <aui:input label="First Name<span class='mandatoryfld'>*</span>" name="firstName" 
								value="<%= contactInfo.getFirstName() %>"></aui:input>
						</td>
						<td width="33%"><br>
					    <aui:input label="Middle Name" 
							value="<%= contactInfo.getMiddleName() %>"
							name="middleName" ></aui:input>
					  </td>
					</tr>
					<tr>
						<td><br>
					  	<aui:input label="Mobile Phone<span class='mandatoryfld'>*</span>" 
								name="phoneMobile"
								value="<%= contactInfo.getPhoneMobile() %>"
								helpMessage=""></aui:input>
						</td>
						<td><br>
					    <aui:input label="Office Phone" name="phoneOffice" 
								value="<%= contactInfo.getPhoneOffice() %>"></aui:input>
						</td>
						<td><br>
					    <aui:input label="House Phone" 
								value="<%= contactInfo.getPhoneHome() %>"
								name="phoneHome"></aui:input>
					  </td>
					</tr>
					<tr>
						<td colspan="2"><br>
							<aui:input style="width:300px" helpMessage="Provide Your Email Address"
								label="Email Address<span class='mandatoryfld'>*</span>" name="emailAddress" 
								value="<%= contactInfo.getEmailAddress() %>"></aui:input>
						</td>
						<td><br>
							<aui:input 
								label="Fax" name="fax" 
								value="<%= contactInfo.getFax() %>"></aui:input>
						</td>
					</tr>
										
          <tr>
          	<td><br>
            	
             	<%
					List<ListType> identifications = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.identification");
					
					%>
					
						<aui:select style="width:130px" name="identificationDocument" label="Identification Document<span class='mandatoryfld'>*</span>" listType="dropdownlist" >
							<option value="">Select Identification Document</option>
				  	
				  	<%
				  	String identification = contactInfo.getIdentificationDoc();
				  	for(int i=0; i<identifications.size(); i++){
				  		ListType _identification = identifications.get(i);
				  	%>	
				  	<aui:option selected="<%=  _identification.getName().equalsIgnoreCase(identification) %>" 
		                  		value="<%=_identification.getName() %>"><%=_identification.getName()  %></aui:option>
				  	<%
				  	}
				  	%>
						</aui:select>
	      		</td>
            <td><br>
           	  <aui:input label="Identification Number<span class='mandatoryfld'>*</span>"
         	    	name="identificationDocumentNo" value="<%= contactInfo.getIdentificationDocNo() %>" ></aui:input> 
            </td>
         	</tr>
          <tr>
          	<td colspan="3" align="right" >
	          	<br><hr>
	            <aui:button type="button" value="Exit Application" onClick="exitApplication();"></aui:button>
             	<aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
            	<aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
             	<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
           	</td>
          </tr>
      	</table>
      </td>
     </tr>
    </table>
 	</div>
</div>
    	
  		
  		   	<script type="text/javascript">
	function setButtonClicked(id)
	{
	   // alert(id);
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>buttonClicked.value=id;
	  // alert(document.<portlet:namespace/>quick_add_account_fm.<portlet:namespace/>buttonClicked.value);
	    //document.getElementById('jspPage').value=id;
	}

	function selectOptions()
	{
	   // alert(id);
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>designation.value='<%= contactInfo.getDesignation() %>';
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>title.value='<%= contactInfo.getTitle() %>';
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>dentificationDoc.value='<%= contactInfo.getIdentificationDoc() %>';
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>designation.value='<%= contactInfo.getFirstName() %>';
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>title.value='<%= contactInfo.getLastName() %>';
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>dentificationDoc.value='<%= contactInfo.getPhoneMobile() %>';
	   document.<portlet:namespace/>saveCompanyContactInformation_fm.<portlet:namespace/>dentificationDoc.value='<%= contactInfo.getEmailAddress() %>';

	   
	}

	selectOptions();
	
	</script>
</aui:form>

	<liferay-portlet:actionURL name="exitApplication" var="exitApplication"></liferay-portlet:actionURL>
	<form name="<portlet:namespace/>exitApplication_fm" method="post"	id="<portlet:namespace/>exitApplication_fm" action="<%=exitApplication.toString()%>"></form>
	<script type="text/javascript">
	<!--
	function exitApplication()
	{
		document.forms["<portlet:namespace/>exitApplication_fm"].submit();
	}
	//-->
	</script>

<script type="text/javascript">
<!--
	function confirmPost()
	{
	var agree=confirm("Cancelling the process will delete the record you have entered into the portal for this application. Do you want to proceed?");
	if (agree){
		document.forms["<portlet:namespace/>deleteApplication_fm"].submit();
		return true ;
	}
	else{
		return false ;
	}
	}
//-->
</script>

<liferay-portlet:actionURL name="deleteApplication" var="deleteApplication"></liferay-portlet:actionURL>
 <aui:form action="<%=deleteApplication.toString() %>" method="post" name="deleteApplication_fm">
  	<aui:input name="applicationId" type="hidden" value="<%= contactInfo.getApplicationId() %>"></aui:input>
 </aui:form>
 
 